package com.tk.ad.sdk.http;

import java.io.File;
import java.io.IOException;
import java.util.Map;

import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.HttpUrl;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;

/**
 * Created by hsy on 2017/3/21.
 */

public class OKHttpUtils {

    private final OkHttpClient mHttpClient = new OkHttpClient();

    private static OKHttpUtils mInstance;

    public static OKHttpUtils getInstance(){
        if(mInstance == null){
            mInstance = new OKHttpUtils();
        }
        return mInstance;
    }

    public static final MediaType JSON= MediaType.parse("application/json; charset=utf-8");


//    public void get(String url, Callback callback){
//        Request request = new Request.Builder().url(url).build();
//        mHttpClient.newCall(request).enqueue(callback);
//    }

    public void get(HttpUrl url, Callback callback){
        Request request = new Request.Builder().url(url).build();
        mHttpClient.newCall(request).enqueue(callback);
    }


//    public void post(String url, Map<String,String> map, Callback callback) throws IOException {
//
//        FormBody.Builder builder = new FormBody.Builder();
//
//        for (Map.Entry<String, String> entry : map.entrySet()) {
//            builder.add(entry.getKey(),entry.getValue());
//        }
//        RequestBody requestBodyPost = builder.build();
//
//        Request requestPost = new Request.Builder()
//                .url(url)
//                .post(requestBodyPost)
//                .build();
//
//        mHttpClient.newCall(requestPost).enqueue(callback);
//    }
//
//    public void post(String url, String json, Callback callback) {
//
//        //创建一个RequestBody(参数1：数据类型 参数2传递的json串)
//        RequestBody requestBody = RequestBody.create(JSON, json);
//        //创建一个请求对象
//        Request request = new Request.Builder()
//                .url(url)
//                .post(requestBody)
//                .build();
//        mHttpClient.newCall(request).enqueue(callback);
//    }

}
